var express = require('express');
var router = express.Router();
var mongoose = require('mongoose');
var LoginSchema = new mongoose.Schema({
  name: {
    type: String,
    required: true
  },
  pwd: {
    type: String,
    required: true,
  },
  gender: {
    type: Boolean,
    required: true
  },
  mobile: {
    type: String,
    required: true
  }
})
var loginModel = mongoose.model('loginModel', LoginSchema);
// POST add
router.post('/', (req, res, next) => {
  var userName = req.body.name;
  var userPwd = req.body.pwd;
  loginModel.findOne({
    name: userName,
    pwd: userPwd
  }, (err, data) => {
    if (err) return next(err);
    if (!data) {
      res.json({
        success: false,
        msg: '您还没有注册，请先去注册'
      })
      return next();
    }
    var userInfo = {
      userId: data._id,
      userName: data.name,
    }
    return res.json({
      success: true,
      msg: '登录成功'
    })
  })
  
});

module.exports = router;
